package biz.obake.team.touchprotector.d.g;

import android.os.Build;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import biz.obake.team.touchprotector.g.c;
import java.util.Map;

public class b extends biz.obake.team.touchprotector.d.b {

    /* renamed from: d  reason: collision with root package name */
    private boolean f1570d = false;
    private PhoneStateListener e = new a(this);

    class a extends PhoneStateListener {
        a(b bVar) {
        }

        public void onCallStateChanged(int i, String str) {
            String str2;
            if (i == 0) {
                biz.obake.team.touchprotector.log.a.b().d("Phone: Idle");
                str2 = "Idle";
            } else if (i == 1) {
                biz.obake.team.touchprotector.log.a.b().d("Phone: Ringing");
                str2 = "Ringing";
            } else if (i == 2) {
                biz.obake.team.touchprotector.log.a.b().d("Phone: OffHook");
                str2 = "OffHook";
            } else {
                return;
            }
            c.g("Phone.State", str2);
        }
    }

    /* renamed from: biz.obake.team.touchprotector.d.g.b$b  reason: collision with other inner class name */
    private class C0066b {

        /* renamed from: a  reason: collision with root package name */
        boolean f1571a;

        /* renamed from: b  reason: collision with root package name */
        boolean f1572b;

        /* renamed from: c  reason: collision with root package name */
        boolean f1573c;

        private C0066b(b bVar) {
            this.f1571a = "Locked".equals(c.c("TPService.State"));
            this.f1572b = biz.obake.team.touchprotector.g.a.g("unlock_on_call");
            this.f1573c = Build.VERSION.SDK_INT >= 23;
        }

        /* synthetic */ C0066b(b bVar, a aVar) {
            this(bVar);
        }
    }

    public static boolean c() {
        String d2 = d();
        if (!c.c("Phone.State").equals(d2)) {
            c.g("Phone.State", d2);
        }
        char c2 = 65535;
        switch (d2.hashCode()) {
            case -1423288430:
                if (d2.equals("Ringing")) {
                    c2 = 0;
                    break;
                }
                break;
            case 79183:
                if (d2.equals("Off")) {
                    c2 = 2;
                    break;
                }
                break;
            case 2274292:
                if (d2.equals("Idle")) {
                    c2 = 3;
                    break;
                }
                break;
            case 114974482:
                if (d2.equals("OffHook")) {
                    c2 = 1;
                    break;
                }
                break;
        }
        return c2 == 0 || c2 == 1;
    }

    private static String d() {
        int callState = ((TelephonyManager) biz.obake.team.android.a.a().getSystemService("phone")).getCallState();
        return callState != 0 ? callState != 1 ? callState != 2 ? "Off" : "OffHook" : "Ringing" : "Idle";
    }

    public static void e(Map<String, String> map) {
        map.put("Phone.State", "Off");
    }

    private void f() {
        if (!this.f1570d) {
            this.f1570d = true;
            biz.obake.team.touchprotector.log.a.b().d("Phone: On");
            ((TelephonyManager) biz.obake.team.android.a.a().getSystemService("phone")).listen(this.e, 32);
        }
    }

    private void g() {
        C0066b bVar = new C0066b(this, (a) null);
        if (bVar.f1571a && bVar.f1572b && bVar.f1573c) {
            f();
        } else {
            h();
        }
    }

    private void h() {
        if (this.f1570d) {
            this.f1570d = false;
            biz.obake.team.touchprotector.log.a.b().d("Phone: Off");
            ((TelephonyManager) biz.obake.team.android.a.a().getSystemService("phone")).listen(this.e, 0);
            c.g("Phone.State", "Off");
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Removed duplicated region for block: B:12:0x0027 A[ADDED_TO_REGION] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void b(java.lang.String r4) {
        /*
            r3 = this;
            int r0 = r4.hashCode()
            r1 = -2066548004(0xffffffff84d2fadc, float:-4.960114E-36)
            r2 = 1
            if (r0 == r1) goto L_0x001a
            r1 = 860355267(0x3347fac3, float:4.6561365E-8)
            if (r0 == r1) goto L_0x0010
            goto L_0x0024
        L_0x0010:
            java.lang.String r0 = "unlock_on_call"
            boolean r4 = r4.equals(r0)
            if (r4 == 0) goto L_0x0024
            r4 = 1
            goto L_0x0025
        L_0x001a:
            java.lang.String r0 = "TPService.State"
            boolean r4 = r4.equals(r0)
            if (r4 == 0) goto L_0x0024
            r4 = 0
            goto L_0x0025
        L_0x0024:
            r4 = -1
        L_0x0025:
            if (r4 == 0) goto L_0x002a
            if (r4 == r2) goto L_0x002a
            goto L_0x002d
        L_0x002a:
            r3.g()
        L_0x002d:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.d.g.b.b(java.lang.String):void");
    }

    public void start() {
        super.start();
        g();
    }

    public void stop() {
        super.stop();
        h();
    }
}
